

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=auto>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/fluid.png">
  <link rel="icon" href="/img/fluid.png">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="author" content="Moe Wang">
  <meta name="keywords" content="">
  
    <meta name="description" content="一、HTML51.1什么是 HTML5？HTML5 将成为 HTML、XHTML 以及 HTML DOM 的新标准。HTML 的上一个版本诞生于 1999 年。自从那以后，Web 世界已经经历了巨变。HTML5 仍处于完善之中。然而，大部分现代浏览器已经具备了某些 HTML5 支持。 1.2 HTML5是如何起步的？HTML5 是 W3C 与 WHATWG（[Web Hypertext Appli">
<meta property="og:type" content="article">
<meta property="og:title" content="HTML5">
<meta property="og:url" content="https://moewang0321.github.io/2019/09/23/2019-09-23-HTML5/index.html">
<meta property="og:site_name" content="moe_大杂烩">
<meta property="og:description" content="一、HTML51.1什么是 HTML5？HTML5 将成为 HTML、XHTML 以及 HTML DOM 的新标准。HTML 的上一个版本诞生于 1999 年。自从那以后，Web 世界已经经历了巨变。HTML5 仍处于完善之中。然而，大部分现代浏览器已经具备了某些 HTML5 支持。 1.2 HTML5是如何起步的？HTML5 是 W3C 与 WHATWG（[Web Hypertext Appli">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2019-09-23T03:56:21.000Z">
<meta property="article:modified_time" content="2023-02-14T08:04:00.844Z">
<meta property="article:author" content="Moe Wang">
<meta property="article:tag" content="HTML">
<meta name="twitter:card" content="summary_large_image">
  
  
  
  <title>HTML5 - moe_大杂烩</title>

  <link  rel="stylesheet" href="https://lib.baomitu.com/twitter-bootstrap/4.6.1/css/bootstrap.min.css" />



  <link  rel="stylesheet" href="https://lib.baomitu.com/github-markdown-css/4.0.0/github-markdown.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/hint.css/2.7.0/hint.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.css" />



<!-- 主题依赖的图标库，不要自行修改 -->
<!-- Do not modify the link that theme dependent icons -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_hj8rtnfg7um.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">


<link  rel="stylesheet" href="/css/main.css" />


  <link id="highlight-css" rel="stylesheet" href="/css/highlight.css" />
  
    <link id="highlight-css-dark" rel="stylesheet" href="/css/highlight-dark.css" />
  




  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    Fluid.ctx = Object.assign({}, Fluid.ctx)
    var CONFIG = {"hostname":"moewang0321.github.io","root":"/","version":"1.9.4","typing":{"enable":true,"typeSpeed":70,"cursorChar":"_","loop":false,"scope":[]},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"left","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"code_language":{"enable":true,"default":"TEXT"},"copy_btn":true,"image_caption":{"enable":true},"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"placement":"right","headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":false,"follow_dnt":true,"baidu":null,"google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname","ignore_local":false}},"search_path":"/local-search.xml"};

    if (CONFIG.web_analytics.follow_dnt) {
      var dntVal = navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack;
      Fluid.ctx.dnt = dntVal && (dntVal.startsWith('1') || dntVal.startsWith('yes') || dntVal.startsWith('on'));
    }
  </script>
  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
  


  
<meta name="generator" content="Hexo 5.4.2"></head>


<body>
  

  <header>
    

<div class="header-inner" style="height: 70vh;">
  <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/">
      <strong>moe_大杂烩</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                <span>首页</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                <span>归档</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-category-fill"></i>
                <span>分类</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                <span>标签</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                <span>关于</span>
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              <i class="iconfont icon-search"></i>
            </a>
          </li>
          
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">
              <i class="iconfont icon-dark" id="color-toggle-icon"></i>
            </a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

  

<div id="banner" class="banner" parallax=true
     style="background: url('/img/default.png') no-repeat center center; background-size: cover;">
  <div class="full-bg-img">
    <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
      <div class="banner-text text-center fade-in-up">
        <div class="h2">
          
            <span id="subtitle" data-typed-text="HTML5"></span>
          
        </div>

        
          
  <div class="mt-3">
    
    
      <span class="post-meta">
        <i class="iconfont icon-date-fill" aria-hidden="true"></i>
        <time datetime="2019-09-23 11:56" pubdate>
          2019年9月23日 中午
        </time>
      </span>
    
  </div>

  <div class="mt-1">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-chart"></i>
        
          14k 字
        
      </span>
    

    
      <span class="post-meta mr-2">
        <i class="iconfont icon-clock-fill"></i>
        
        
        
          121 分钟
        
      </span>
    

    
    
  </div>


        
      </div>

      
    </div>
  </div>
</div>

</div>

  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="side-col d-none d-lg-block col-lg-2">
      

    </div>

    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">HTML5</h1>
            
            
              <div class="markdown-body">
                
                <h1 id="一、HTML5"><a href="#一、HTML5" class="headerlink" title="一、HTML5"></a>一、HTML5</h1><h4 id="1-1什么是-HTML5？"><a href="#1-1什么是-HTML5？" class="headerlink" title="1.1什么是 HTML5？"></a>1.1什么是 HTML5？</h4><p>HTML5 将成为 HTML、XHTML 以及 HTML DOM 的新标准。<br>HTML 的上一个版本诞生于 1999 年。自从那以后，Web 世界已经经历了巨变。<br>HTML5 仍处于完善之中。然而，大部分现代浏览器已经具备了某些 HTML5 支持。</p>
<h4 id="1-2-HTML5是如何起步的？"><a href="#1-2-HTML5是如何起步的？" class="headerlink" title="1.2 HTML5是如何起步的？"></a>1.2 HTML5是如何起步的？</h4><p>HTML5 是 W3C 与 WHATWG（[Web Hypertext Application Technology Working Group]网页超文本应用技术工作小组） 合作的结果。</p>
<p>WHATWG 致力于 web 表单和应用程序，而 W3C 专注于 XHTML 2.0。在 2006 年，双方决定进行合作，来创建一个新版本的 HTML。</p>
<p>为 HTML5 建立的一些规则：</p>
<ul>
<li>新特性应该基于 HTML、CSS、DOM 以及 JavaScript。</li>
<li>减少对外部插件的需求（比如 Flash）</li>
<li>更优秀的错误处理</li>
<li>更多取代脚本的标记</li>
<li>HTML5 应该独立于设备</li>
<li>开发进程应对公众透明</li>
</ul>
<h4 id="1-3-新特性"><a href="#1-3-新特性" class="headerlink" title="1.3 新特性"></a>1.3 新特性</h4><p>HTML5 中的一些有趣的新特性：</p>
<ul>
<li>用于绘画的 canvas 元素</li>
<li>用于媒介回放的 video 和 audio 元素</li>
<li>对本地离线存储的更好的支持</li>
<li>新的特殊内容元素，比如 article、footer、header、nav、section</li>
<li>新的表单控件，比如 calendar、date、time、email、url、search</li>
</ul>
<h4 id="1-4-HTML5新增语义化标签"><a href="#1-4-HTML5新增语义化标签" class="headerlink" title="1.4 HTML5新增语义化标签"></a>1.4 HTML5新增语义化标签</h4><table>
<thead>
<tr>
<th align="left"><strong>标签</strong></th>
<th align="left"><strong>描述</strong></th>
</tr>
</thead>
<tbody><tr>
<td align="left"><code>&lt;article&gt;</code></td>
<td align="left">定义article</td>
</tr>
<tr>
<td align="left"><code>&lt;aside&gt;</code></td>
<td align="left">定义页面内容之外的内容。</td>
</tr>
<tr>
<td align="left"><code>&lt;audio&gt;</code></td>
<td align="left">定义声音内容。</td>
</tr>
<tr>
<td align="left"><code>&lt;bdi&gt;</code></td>
<td align="left">定义文本的文本方向，使其脱离其周围文本的方向设置。(浏览器支持不好)</td>
</tr>
<tr>
<td align="left"><code>&lt;canvas&gt;</code></td>
<td align="left">定义画布</td>
</tr>
<tr>
<td align="left"><code>&lt;command&gt;</code></td>
<td align="left">定义命令按钮。(目前，主流浏览器都不支持 <command> 标签。)</td>
</tr>
<tr>
<td align="left"><code>&lt;datalist&gt;</code></td>
<td align="left">定义下拉列表。</td>
</tr>
<tr>
<td align="left"><code>&lt;details&gt;</code></td>
<td align="left">定义元素的细节。</td>
</tr>
<tr>
<td align="left"><code>&lt;embed&gt;</code></td>
<td align="left">定义外部交互内容或插件。</td>
</tr>
<tr>
<td align="left"><code>&lt;figcaption&gt;</code></td>
<td align="left">定义figure 元素的标题。</td>
</tr>
<tr>
<td align="left"><code>&lt;figure&gt;</code></td>
<td align="left">定义媒介内容的分组，以及它们的标题。</td>
</tr>
<tr>
<td align="left"><code>&lt;footer&gt;</code></td>
<td align="left">定义   section 或 page 的页脚。</td>
</tr>
<tr>
<td align="left"><code>&lt;header&gt;</code></td>
<td align="left">定义   section 或 page 的页眉。</td>
</tr>
<tr>
<td align="left"><code>&lt;hgroup&gt;</code></td>
<td align="left">定义有关文档中的   section 的信息。</td>
</tr>
<tr>
<td align="left"><code>&lt;keygen&gt;</code></td>
<td align="left">定义生成密钥。</td>
</tr>
<tr>
<td align="left"><code>&lt;main&gt;</code></td>
<td align="left">定义文档的主要内容。</td>
</tr>
<tr>
<td align="left"><code>&lt;mark&gt;</code></td>
<td align="left">定义有记号的文本。</td>
</tr>
<tr>
<td align="left"><code>&lt;meter&gt;</code></td>
<td align="left">定义预定义范围内的度量。</td>
</tr>
<tr>
<td align="left"><code>&lt;nav&gt;</code></td>
<td align="left">定义导航链接。</td>
</tr>
<tr>
<td align="left"><code>&lt;output&gt;</code></td>
<td align="left">定义输出的一些类型。</td>
</tr>
<tr>
<td align="left"><code>&lt;progress&gt;</code></td>
<td align="left">定义任何类型的任务的进度。</td>
</tr>
<tr>
<td align="left"><code>&lt;rp&gt;</code></td>
<td align="left">定义若浏览器不支持 ruby 元素显示的内容。</td>
</tr>
<tr>
<td align="left"><code>&lt;rt&gt;</code></td>
<td align="left">定义 ruby 注释的解释。</td>
</tr>
<tr>
<td align="left"><code>&lt;ruby&gt;</code></td>
<td align="left">定义 ruby 注释。</td>
</tr>
<tr>
<td align="left"><code>&lt;section&gt;</code></td>
<td align="left">定义   section。</td>
</tr>
<tr>
<td align="left"><code>&lt;source&gt;</code></td>
<td align="left">定义媒介源。</td>
</tr>
<tr>
<td align="left"><code>&lt;summary&gt;</code></td>
<td align="left">定义   details 元素的标题。</td>
</tr>
<tr>
<td align="left"><code>&lt;time&gt;</code></td>
<td align="left">定义日期/时间。</td>
</tr>
<tr>
<td align="left"><code>&lt;track&gt;</code></td>
<td align="left">定义用在媒体播放器中的文本轨道。</td>
</tr>
<tr>
<td align="left"><code>&lt;video&gt;</code></td>
<td align="left">定义视频。</td>
</tr>
</tbody></table>
<h4 id="1-5-browser-sync"><a href="#1-5-browser-sync" class="headerlink" title="1.5 browser-sync"></a>1.5 browser-sync</h4><h4 id="1-6-HTML5表单"><a href="#1-6-HTML5表单" class="headerlink" title="1.6 HTML5表单"></a>1.6 HTML5表单</h4><h5 id="HTML5-新的-Input-类型"><a href="#HTML5-新的-Input-类型" class="headerlink" title="HTML5 新的 Input 类型"></a>HTML5 新的 Input 类型</h5><p>HTML5 拥有多个新的表单输入类型。这些新特性提供了更好的输入控制和验证：</p>
<ul>
<li>email</li>
<li>url</li>
<li>number</li>
<li>range</li>
<li>Date pickers (date, month, week, time, datetime, datetime-local)</li>
<li>search</li>
<li>color</li>
</ul>
<h5 id="1-6-2-Input-类型-email"><a href="#1-6-2-Input-类型-email" class="headerlink" title="1.6.2 Input 类型 - email"></a>1.6.2 Input 类型 - email</h5><p>email 类型用于应该包含 e-mail 地址的输入域。</p>
<p>在提交表单时，会自动验证 email 域的值。</p>
<figure class="highlight pgsql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs pgsql">E-mail: &lt;<span class="hljs-keyword">input</span> <span class="hljs-keyword">type</span>=&quot;email&quot; <span class="hljs-type">name</span>=&quot;user_email&quot; /&gt;<br></code></pre></td></tr></table></figure>

<p><strong>Input 类型 - url</strong></p>
<p>url 类型用于应该包含 URL 地址的输入域。</p>
<p>在提交表单时，会自动验证 url 域的值。</p>
<figure class="highlight pgsql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs pgsql">Homepage: &lt;<span class="hljs-keyword">input</span> <span class="hljs-keyword">type</span>=&quot;url&quot; <span class="hljs-type">name</span>=&quot;user_url&quot; /&gt;<br></code></pre></td></tr></table></figure>

<p><strong>Input 类型 - number</strong></p>
<p>number 类型用于应该包含数值的输入域。</p>
<p>您还能够设定对所接受的数字的限定：</p>
<figure class="highlight lua"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs lua">Points: &lt;<span class="hljs-built_in">input</span> <span class="hljs-built_in">type</span>=<span class="hljs-string">&quot;number&quot;</span> name=<span class="hljs-string">&quot;points&quot;</span> <span class="hljs-built_in">min</span>=<span class="hljs-string">&quot;1&quot;</span> <span class="hljs-built_in">max</span>=<span class="hljs-string">&quot;10&quot;</span> /&gt;<br></code></pre></td></tr></table></figure>

<p>请使用下面的属性来规定对数字类型的限定：</p>
<table>
<thead>
<tr>
<th align="left">属性</th>
<th align="left">值</th>
<th align="left">描述</th>
</tr>
</thead>
<tbody><tr>
<td align="left">max</td>
<td align="left"><em>number</em></td>
<td align="left">规定允许的最大值</td>
</tr>
<tr>
<td align="left">min</td>
<td align="left"><em>number</em></td>
<td align="left">规定允许的最小值</td>
</tr>
<tr>
<td align="left">step</td>
<td align="left"><em>number</em></td>
<td align="left">规定合法的数字间隔（如果 step=”3”，则合法的数是 -3,0,3,6 等）</td>
</tr>
<tr>
<td align="left">value</td>
<td align="left"><em>number</em></td>
<td align="left">规定默认值</td>
</tr>
</tbody></table>
<p><strong>Input 类型 - range</strong></p>
<p>range 类型用于应该包含一定范围内数字值的输入域。</p>
<p>range 类型显示为滑动条。</p>
<p>您还能够设定对所接受的数字的限定：</p>
<figure class="highlight abnf"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs abnf">&lt;input type<span class="hljs-operator">=</span><span class="hljs-string">&quot;range&quot;</span> name<span class="hljs-operator">=</span><span class="hljs-string">&quot;points&quot;</span> min<span class="hljs-operator">=</span><span class="hljs-string">&quot;1&quot;</span> max<span class="hljs-operator">=</span><span class="hljs-string">&quot;10&quot;</span> /&gt;<br></code></pre></td></tr></table></figure>

<p>请使用下面的属性来规定对数字类型的限定：</p>
<table>
<thead>
<tr>
<th align="left">属性</th>
<th align="left">值</th>
<th align="left">描述</th>
</tr>
</thead>
<tbody><tr>
<td align="left">max</td>
<td align="left"><em>number</em></td>
<td align="left">规定允许的最大值</td>
</tr>
<tr>
<td align="left">min</td>
<td align="left"><em>number</em></td>
<td align="left">规定允许的最小值</td>
</tr>
<tr>
<td align="left">step</td>
<td align="left"><em>number</em></td>
<td align="left">规定合法的数字间隔（如果 step=”3”，则合法的数是 -3,0,3,6 等）</td>
</tr>
<tr>
<td align="left">value</td>
<td align="left"><em>number</em></td>
<td align="left">规定默认值</td>
</tr>
</tbody></table>
<p><strong>Input 类型 - Date Pickers（日期选择器）</strong></p>
<p>HTML5 拥有多个可供选取日期和时间的新输入类型：</p>
<ul>
<li>date - 选取日、月、年</li>
<li>month - 选取月、年</li>
<li>week - 选取周和年</li>
<li>time - 选取时间（小时和分钟）</li>
<li>datetime - 选取时间、日、月、年（UTC 时间）</li>
<li>datetime-local - 选取时间、日、月、年（本地时间）</li>
</ul>
<p>下面的例子允许您从日历中选取一个日期：</p>
<figure class="highlight pgsql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs pgsql"><span class="hljs-type">Date</span>: &lt;<span class="hljs-keyword">input</span> <span class="hljs-keyword">type</span>=&quot;date&quot; <span class="hljs-type">name</span>=&quot;user_date&quot; /&gt;<br></code></pre></td></tr></table></figure>



<p>color: 颜色选择器</p>
<figure class="highlight routeros"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs routeros">Color: &lt;input <span class="hljs-attribute">type</span>=<span class="hljs-string">&quot;color&quot;</span> <span class="hljs-attribute">onchange</span>=<span class="hljs-string">&quot;getColor()&quot;</span>  <span class="hljs-attribute">id</span>=<span class="hljs-string">&quot;colorSelector&quot;</span>&gt;  &lt;br&gt;<br></code></pre></td></tr></table></figure>

<p>Input 类型 - search**</p>
<p>search 类型用于搜索域，比如站点搜索或 Google 搜索。</p>
<p>search 域显示为常规的文本域。</p>
<h5 id="1-6-3-HTML5-新的表单元素"><a href="#1-6-3-HTML5-新的表单元素" class="headerlink" title="1.6.3 HTML5 新的表单元素"></a>1.6.3 HTML5 新的表单元素</h5><p>HTML5 拥有若干涉及表单的元素和属性。</p>
<ul>
<li>datalist</li>
<li>keygen</li>
<li>output</li>
</ul>
<p><strong>datalist 元素</strong></p>
<p>datalist 元素规定输入域的选项列表。</p>
<p>列表是通过 datalist 内的 option 元素创建的。</p>
<p>如需把 datalist 绑定到输入域，请用输入域的 list 属性引用 datalist 的 id：</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><code class="hljs xml">Webpage: <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;url&quot;</span> <span class="hljs-attr">list</span>=<span class="hljs-string">&quot;url_list&quot;</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;link&quot;</span> /&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">datalist</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;url_list&quot;</span>&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">option</span> <span class="hljs-attr">label</span>=<span class="hljs-string">&quot;baidu&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;http://www.baidu.com&quot;</span> /&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">option</span> <span class="hljs-attr">label</span>=<span class="hljs-string">&quot;tencent&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;http://www.qq.com&quot;</span> /&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">option</span> <span class="hljs-attr">label</span>=<span class="hljs-string">&quot;alibaba&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;http://www.alibaba.com&quot;</span> /&gt;</span><br><span class="hljs-tag">&lt;/<span class="hljs-name">datalist</span>&gt;</span><br></code></pre></td></tr></table></figure>

<p><strong>output 元素</strong></p>
<p>output 元素用于不同类型的输出，比如计算或脚本输出：</p>
<figure class="highlight routeros"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs routeros">&lt;output <span class="hljs-attribute">id</span>=<span class="hljs-string">&quot;result&quot;</span> <span class="hljs-attribute">onforminput</span>=<span class="hljs-string">&quot;resCalc()&quot;</span>&gt;&lt;/output&gt;<br></code></pre></td></tr></table></figure>

<h5 id="1-6-4-HTML5-新的表单属性"><a href="#1-6-4-HTML5-新的表单属性" class="headerlink" title="1.6.4 HTML5 新的表单属性"></a>1.6.4 HTML5 新的表单属性</h5><p><strong>新的 form 属性：</strong></p>
<ul>
<li>autocomplete</li>
<li>novalidate</li>
</ul>
<p><strong>新的 input 属性：</strong></p>
<ul>
<li>autocomplete</li>
<li>autofocus</li>
<li>form</li>
<li>form overrides (formaction, formenctype, formmethod, formnovalidate, formtarget)</li>
<li>height 和 width</li>
<li>list</li>
<li>min, max 和 step</li>
<li>multiple</li>
<li>pattern (regexp)</li>
<li>placeholder</li>
<li>required</li>
</ul>
<p><strong>autocomplete 属性</strong></p>
<p>autocomplete 属性规定 form 或 input 域应该拥有自动完成功能。</p>
<p><strong>注释：</strong>autocomplete 适用于 <code>&lt;form&gt; </code>标签，以及以下类型的 <code>&lt;input&gt;</code> 标签：text, search, url, telephone, email, password, datepickers, range 以及 color。</p>
<p>当用户在自动完成域中开始输入时，浏览器应该在该域中显示填写的选项：</p>
<figure class="highlight pgsql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><code class="hljs pgsql">&lt;form action=&quot;demo_form.php&quot; <span class="hljs-keyword">method</span>=&quot;get&quot; autocomplete=&quot;on&quot;&gt;<br>First <span class="hljs-type">name</span>: &lt;<span class="hljs-keyword">input</span> <span class="hljs-keyword">type</span>=&quot;text&quot; <span class="hljs-type">name</span>=&quot;fname&quot; /&gt;&lt;br /&gt;<br>Last <span class="hljs-type">name</span>: &lt;<span class="hljs-keyword">input</span> <span class="hljs-keyword">type</span>=&quot;text&quot; <span class="hljs-type">name</span>=&quot;lname&quot; /&gt;&lt;br /&gt;<br>E-mail: &lt;<span class="hljs-keyword">input</span> <span class="hljs-keyword">type</span>=&quot;email&quot; <span class="hljs-type">name</span>=&quot;email&quot; autocomplete=&quot;off&quot; /&gt;&lt;br /&gt;<br>&lt;<span class="hljs-keyword">input</span> <span class="hljs-keyword">type</span>=&quot;submit&quot; /&gt;<br>&lt;/form&gt;<br></code></pre></td></tr></table></figure>

<p><strong>注释：</strong>在某些浏览器中，您可能需要启用自动完成功能，以使该属性生效。(firefox支持较好)</p>
<p><strong>autofocus 属性</strong></p>
<p>autofocus 属性规定在页面加载时，域自动地获得焦点。</p>
<p><strong>注释：</strong>autofocus 属性适用于所有 <code>&lt;input&gt;</code> 标签的类型。</p>
<figure class="highlight pgsql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs pgsql"><span class="hljs-keyword">User</span> <span class="hljs-type">name</span>: &lt;<span class="hljs-keyword">input</span> <span class="hljs-keyword">type</span>=&quot;text&quot; <span class="hljs-type">name</span>=&quot;user_name&quot;  autofocus=&quot;autofocus&quot; /&gt;<br></code></pre></td></tr></table></figure>

<p><strong>form 属性</strong></p>
<p>form 属性规定输入域所属的一个或多个表单。</p>
<p><strong>注释：</strong>form 属性适用于所有 <code>&lt;input&gt; </code>标签的类型。</p>
<p>form 属性必须引用所属表单的 id：</p>
<figure class="highlight pgsql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><code class="hljs pgsql">&lt;form action=&quot;demo_form.php&quot; <span class="hljs-keyword">method</span>=&quot;get&quot; id=&quot;user_form&quot;&gt;<br>First <span class="hljs-type">name</span>:&lt;<span class="hljs-keyword">input</span> <span class="hljs-keyword">type</span>=&quot;text&quot; <span class="hljs-type">name</span>=&quot;fname&quot; /&gt;<br>&lt;<span class="hljs-keyword">input</span> <span class="hljs-keyword">type</span>=&quot;submit&quot; /&gt;<br>&lt;/form&gt;<br>Last <span class="hljs-type">name</span>: &lt;<span class="hljs-keyword">input</span> <span class="hljs-keyword">type</span>=&quot;text&quot; <span class="hljs-type">name</span>=&quot;lname&quot; form=&quot;user_form&quot; /&gt;<br></code></pre></td></tr></table></figure>

<p><strong>注释：</strong>如需引用一个以上的表单，请使用空格分隔的列表。</p>
<p><strong>表单重写属性</strong></p>
<p>表单重写属性（form override attributes）允许您重写 form 元素的某些属性设定。</p>
<p>表单重写属性有：</p>
<ul>
<li>formaction - 重写表单的 action 属性</li>
<li>formenctype - 重写表单的 enctype 属性</li>
<li>formmethod - 重写表单的 method 属性</li>
<li>formnovalidate - 重写表单的 novalidate 属性</li>
<li>formtarget - 重写表单的 target 属性</li>
</ul>
<p><strong>注释：</strong>表单重写属性适用于以下类型的 <code>&lt;input&gt;</code> 标签：submit 和 image。</p>
<figure class="highlight stata"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><code class="hljs stata">&lt;<span class="hljs-keyword">form</span> action=<span class="hljs-string">&quot;demo_form.php&quot;</span> method=<span class="hljs-string">&quot;get&quot;</span> id=<span class="hljs-string">&quot;user_form&quot;</span>&gt;<br><span class="hljs-keyword">E</span>-mail: &lt;<span class="hljs-keyword">input</span> <span class="hljs-keyword">type</span>=<span class="hljs-string">&quot;email&quot;</span> name=<span class="hljs-string">&quot;userid&quot;</span> /&gt;&lt;<span class="hljs-keyword">br</span> /&gt;<br>&lt;<span class="hljs-keyword">input</span> <span class="hljs-keyword">type</span>=<span class="hljs-string">&quot;submit&quot;</span> value=<span class="hljs-string">&quot;Submit&quot;</span> /&gt;<br>&lt;<span class="hljs-keyword">br</span> /&gt;<br>&lt;<span class="hljs-keyword">input</span> <span class="hljs-keyword">type</span>=<span class="hljs-string">&quot;submit&quot;</span> formaction=<span class="hljs-string">&quot;demo_admin.php&quot;</span> value=<span class="hljs-string">&quot;Submit as admin&quot;</span> /&gt;<br>&lt;<span class="hljs-keyword">br</span> /&gt;<br>&lt;<span class="hljs-keyword">input</span> <span class="hljs-keyword">type</span>=<span class="hljs-string">&quot;submit&quot;</span> formnovalidate=<span class="hljs-string">&quot;true&quot;</span> value=<span class="hljs-string">&quot;Submit without validation&quot;</span> /&gt;<br>&lt;<span class="hljs-keyword">br</span> /&gt;<br>&lt;/<span class="hljs-keyword">form</span>&gt;<br></code></pre></td></tr></table></figure>

<p><strong>注释：</strong>这些属性对于创建不同的提交按钮很有帮助。</p>
<p><strong>height 和 width 属性</strong></p>
<p>height 和 width 属性规定用于 image 类型的 input 标签的图像高度和宽度。</p>
<p><strong>注释：</strong>height 和 width 属性只适用于 image 类型的 <code>&lt;input&gt;</code> 标签。</p>
<figure class="highlight abnf"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs abnf">&lt;input type<span class="hljs-operator">=</span><span class="hljs-string">&quot;image&quot;</span> src<span class="hljs-operator">=</span><span class="hljs-string">&quot;img_submit.gif&quot;</span> width<span class="hljs-operator">=</span><span class="hljs-string">&quot;99&quot;</span> height<span class="hljs-operator">=</span><span class="hljs-string">&quot;99&quot;</span> /&gt;<br></code></pre></td></tr></table></figure>

<p><strong>list 属性</strong></p>
<p>list 属性规定输入域的 datalist。datalist 是输入域的选项列表。</p>
<p><strong>注释：</strong>list 属性适用于以下类型的 <code>&lt;input&gt;</code> 标签：text, search, url, telephone, email, date pickers, number, range 以及 color。</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><code class="hljs xml">Webpage: <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;url&quot;</span> <span class="hljs-attr">list</span>=<span class="hljs-string">&quot;url_list&quot;</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;link&quot;</span> /&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">datalist</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;url_list&quot;</span>&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">option</span> <span class="hljs-attr">label</span>=<span class="hljs-string">&quot;baidu&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;http://www.baidu.com&quot;</span> /&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">option</span> <span class="hljs-attr">label</span>=<span class="hljs-string">&quot;tencent&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;http://www.qq.com&quot;</span> /&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">option</span> <span class="hljs-attr">label</span>=<span class="hljs-string">&quot;alibaba&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;http://www.alibaba.com&quot;</span> /&gt;</span><br><span class="hljs-tag">&lt;/<span class="hljs-name">datalist</span>&gt;</span><br></code></pre></td></tr></table></figure>

<p><strong>min、max 和 step 属性</strong></p>
<p>min、max 和 step 属性用于为包含数字或日期的 input 类型规定限定（约束）。</p>
<p>max 属性规定输入域所允许的最大值。</p>
<p>min 属性规定输入域所允许的最小值。</p>
<p>step 属性为输入域规定合法的数字间隔（如果 step=”3”，则合法的数是 -3,0,3,6 等）。</p>
<p><strong>注释：</strong>min、max 和 step 属性适用于以下类型的<code> &lt;input&gt;</code> 标签：date pickers、number 以及 range。</p>
<p>下面的例子显示一个数字域，该域接受介于 0 到 10 之间的值，且步进为 3（即合法的值为 0、3、6 和 9）：</p>
<figure class="highlight routeros"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs routeros">Points: &lt;input <span class="hljs-attribute">type</span>=<span class="hljs-string">&quot;number&quot;</span> <span class="hljs-attribute">name</span>=<span class="hljs-string">&quot;points&quot;</span> <span class="hljs-attribute">min</span>=<span class="hljs-string">&quot;0&quot;</span> <span class="hljs-attribute">max</span>=<span class="hljs-string">&quot;10&quot;</span> <span class="hljs-attribute">step</span>=<span class="hljs-string">&quot;3&quot;</span> /&gt;<br></code></pre></td></tr></table></figure>

<p><strong>multiple 属性</strong></p>
<p>multiple 属性规定输入域中可选择多个值。</p>
<p><strong>注释：</strong>multiple 属性适用于以下类型的 <code>&lt;input&gt;</code> 标签：email 和 file。</p>
<figure class="highlight pgsql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs pgsql"><span class="hljs-keyword">Select</span> images: &lt;<span class="hljs-keyword">input</span> <span class="hljs-keyword">type</span>=&quot;file&quot; <span class="hljs-type">name</span>=&quot;img&quot; multiple=&quot;multiple&quot; /&gt;<br></code></pre></td></tr></table></figure>

<p><strong>novalidate 属性</strong></p>
<p>novalidate 属性规定在提交表单时不应该验证 form 或 input 域。</p>
<p><strong>注释：</strong>novalidate 属性适用于 <code>&lt;form&gt;</code> 以及以下类型的 <code>&lt;input&gt;</code> 标签：text, search, url, telephone, email, password, date pickers, range 以及 color.</p>
<figure class="highlight pgsql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><code class="hljs pgsql">&lt;form action=&quot;demo_form.php&quot; <span class="hljs-keyword">method</span>=&quot;get&quot; novalidate=&quot;true&quot;&gt;<br>E-mail: &lt;<span class="hljs-keyword">input</span> <span class="hljs-keyword">type</span>=&quot;email&quot; <span class="hljs-type">name</span>=&quot;user_email&quot; /&gt;<br>&lt;<span class="hljs-keyword">input</span> <span class="hljs-keyword">type</span>=&quot;submit&quot; /&gt;<br>&lt;/form&gt;<br></code></pre></td></tr></table></figure>

<p><strong>pattern 属性</strong></p>
<p>pattern 属性规定用于验证 input 域的模式（pattern）。</p>
<p>模式（pattern） 是正则表达式。</p>
<p><strong>注释：</strong>pattern 属性适用于以下类型的 <code>&lt;input&gt;</code> 标签：text, search, url, telephone, email 以及 password。</p>
<p>下面的例子显示了一个只能包含三个字母的文本域（不含数字及特殊字符）：</p>
<figure class="highlight routeros"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs routeros">Country code: &lt;input <span class="hljs-attribute">type</span>=<span class="hljs-string">&quot;text&quot;</span> <span class="hljs-attribute">name</span>=<span class="hljs-string">&quot;country_code&quot;</span><br><span class="hljs-attribute">pattern</span>=<span class="hljs-string">&quot;[A-z]&#123;3&#125;&quot;</span> <span class="hljs-attribute">title</span>=<span class="hljs-string">&quot;Three letter country code&quot;</span> /&gt;<br></code></pre></td></tr></table></figure>

<p><strong>placeholder 属性</strong></p>
<p>placeholder 属性提供一种提示（hint），描述输入域所期待的值。</p>
<p><strong>注释：</strong>placeholder 属性适用于以下类型的 <code>&lt;input&gt;</code> 标签：text, search, url, telephone, email 以及 password。</p>
<p>提示（hint）会在输入域为空时显示出现，会在输入域获得焦点时消失：</p>
<figure class="highlight abnf"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs abnf">&lt;input type<span class="hljs-operator">=</span><span class="hljs-string">&quot;search&quot;</span> name<span class="hljs-operator">=</span><span class="hljs-string">&quot;user_search&quot;</span>  placeholder<span class="hljs-operator">=</span><span class="hljs-string">&quot;Search&quot;</span> /&gt;<br></code></pre></td></tr></table></figure>

<p><strong>required 属性</strong></p>
<p>required 属性规定必须在提交之前填写输入域（不能为空）。</p>
<p><strong>注释：</strong>required 属性适用于以下类型的<code> &lt;input&gt;</code> 标签：text, search, url, telephone, email, password, date pickers, number, checkbox, radio 以及 file。</p>
<figure class="highlight pgsql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs pgsql"><span class="hljs-type">Name</span>: &lt;<span class="hljs-keyword">input</span> <span class="hljs-keyword">type</span>=&quot;text&quot; <span class="hljs-type">name</span>=&quot;usr_name&quot; required=&quot;required&quot; /&gt;<br></code></pre></td></tr></table></figure>

<h4 id="1-7-HTML5-全局属性"><a href="#1-7-HTML5-全局属性" class="headerlink" title="1.7 HTML5 全局属性"></a>1.7 HTML5 全局属性</h4><p>HTML5 中添加的属性。</p>
<table>
<thead>
<tr>
<th align="left">属性</th>
<th align="left">描述</th>
</tr>
</thead>
<tbody><tr>
<td align="left">contenteditable</td>
<td align="left">规定元素内容是否可编辑。</td>
</tr>
<tr>
<td align="left">contextmenu</td>
<td align="left">规定元素的上下文菜单。上下文菜单在用户点击元素时显示。(浏览器不支持)</td>
</tr>
<tr>
<td align="left">data-*</td>
<td align="left">用于存储页面或应用程序的私有定制数据。</td>
</tr>
<tr>
<td align="left">draggable</td>
<td align="left">规定元素是否可拖动。</td>
</tr>
<tr>
<td align="left">dropzone</td>
<td align="left">规定在拖动被拖动数据时是否进行复制、移动或链接。</td>
</tr>
<tr>
<td align="left">hidden</td>
<td align="left">隐藏元素</td>
</tr>
<tr>
<td align="left">spellcheck</td>
<td align="left">规定是否对元素进行拼写和语法检查。</td>
</tr>
<tr>
<td align="left">translate</td>
<td align="left">规定是否应该翻译元素内容。</td>
</tr>
</tbody></table>
<h4 id="1-8-HTML5事件"><a href="#1-8-HTML5事件" class="headerlink" title="1.8 HTML5事件"></a>1.8 HTML5事件</h4><h5 id="1-8-1-window-事件属性"><a href="#1-8-1-window-事件属性" class="headerlink" title="1.8.1 window 事件属性"></a>1.8.1 window 事件属性</h5><p>针对 window 对象触发的事件（应用到 <body> 标签）：</p>
<table>
<thead>
<tr>
<th align="left">属性</th>
<th align="left">值</th>
<th align="left">描述</th>
</tr>
</thead>
<tbody><tr>
<td align="left">onafterprint</td>
<td align="left">script</td>
<td align="left">文档打印之后运行的脚本。(火狐)</td>
</tr>
<tr>
<td align="left">onbeforeprint</td>
<td align="left">script</td>
<td align="left">文档打印之前运行的脚本。(火狐)</td>
</tr>
<tr>
<td align="left">onbeforeunload</td>
<td align="left">script</td>
<td align="left">文档卸载之前运行的脚本。 (chrome)</td>
</tr>
<tr>
<td align="left">onerror</td>
<td align="left">script</td>
<td align="left">在错误发生时运行的脚本。</td>
</tr>
<tr>
<td align="left">onhashchange</td>
<td align="left">script</td>
<td align="left">当文档已改变时运行的脚本。</td>
</tr>
<tr>
<td align="left">onmessage</td>
<td align="left">script</td>
<td align="left">在消息被触发时运行的脚本。</td>
</tr>
<tr>
<td align="left">onoffline</td>
<td align="left">script</td>
<td align="left">当文档离线时运行的脚本。(火狐)</td>
</tr>
<tr>
<td align="left">ononline</td>
<td align="left">script</td>
<td align="left">当文档上线时运行的脚本。(火狐)</td>
</tr>
<tr>
<td align="left">onpagehide</td>
<td align="left">script</td>
<td align="left">当窗口隐藏时运行的脚本。(火狐/chrome)</td>
</tr>
<tr>
<td align="left">onpageshow</td>
<td align="left">script</td>
<td align="left">当窗口成为可见时运行的脚本。(火狐/chrome)</td>
</tr>
<tr>
<td align="left">onpopstate</td>
<td align="left">script</td>
<td align="left">当窗口历史记录改变时运行的脚本。</td>
</tr>
<tr>
<td align="left">onredo</td>
<td align="left">script</td>
<td align="left">当文档执行撤销（redo）时运行的脚本。</td>
</tr>
<tr>
<td align="left">onstorage</td>
<td align="left">script</td>
<td align="left">在 Web Storage 区域更新后运行的脚本。</td>
</tr>
<tr>
<td align="left">onundo</td>
<td align="left">script</td>
<td align="left">在文档执行 undo 时运行的脚本。</td>
</tr>
</tbody></table>
<h5 id="1-8-2-Form-事件"><a href="#1-8-2-Form-事件" class="headerlink" title="1.8.2 Form 事件"></a>1.8.2 Form 事件</h5><p>由 HTML 表单内的动作触发的事件（应用到几乎所有 HTML 元素，但最常用在 form 元素中）：</p>
<table>
<thead>
<tr>
<th align="left">属性</th>
<th align="left">值</th>
<th align="left">描述</th>
</tr>
</thead>
<tbody><tr>
<td align="left">oncontextmenu</td>
<td align="left">script</td>
<td align="left">当上下文菜单被触发时运行的脚本。(鼠标右键触发)</td>
</tr>
<tr>
<td align="left">onformchange</td>
<td align="left">script</td>
<td align="left">在表单改变时运行的脚本。</td>
</tr>
<tr>
<td align="left">onforminput</td>
<td align="left">script</td>
<td align="left">当表单获得用户输入时运行的脚本。</td>
</tr>
<tr>
<td align="left">oninvalid</td>
<td align="left">script</td>
<td align="left">当元素无效时运行的脚本。</td>
</tr>
</tbody></table>
<p>oncontextmenu事件：</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br></pre></td><td class="code"><pre><code class="hljs xml"><span class="hljs-meta">&lt;!DOCTYPE <span class="hljs-keyword">html</span>&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">html</span> <span class="hljs-attr">lang</span>=<span class="hljs-string">&quot;en&quot;</span>&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">charset</span>=<span class="hljs-string">&quot;UTF-8&quot;</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;viewport&quot;</span> <span class="hljs-attr">content</span>=<span class="hljs-string">&quot;width=device-width, initial-scale=1.0&quot;</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">http-equiv</span>=<span class="hljs-string">&quot;X-UA-Compatible&quot;</span> <span class="hljs-attr">content</span>=<span class="hljs-string">&quot;ie=edge&quot;</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>Document<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">style</span>&gt;</span><span class="language-css"></span><br><span class="language-css">        <span class="hljs-selector-tag">ul</span>, <span class="hljs-selector-tag">li</span> &#123;</span><br><span class="language-css">            <span class="hljs-attribute">margin</span>: <span class="hljs-number">0</span>;</span><br><span class="language-css">            <span class="hljs-attribute">padding</span>: <span class="hljs-number">0</span>;</span><br><span class="language-css">        &#125;</span><br><span class="language-css"></span><br><span class="language-css">        <span class="hljs-selector-id">#myMenu</span>&#123;</span><br><span class="language-css">            <span class="hljs-attribute">list-style</span>: none;</span><br><span class="language-css">            <span class="hljs-attribute">width</span>: <span class="hljs-number">150px</span>;</span><br><span class="language-css">            <span class="hljs-attribute">border</span>: <span class="hljs-number">1px</span> solid <span class="hljs-number">#ccc</span>;</span><br><span class="language-css">            <span class="hljs-attribute">border-bottom</span>: none;</span><br><span class="language-css">            <span class="hljs-attribute">position</span>: absolute;</span><br><span class="language-css">            <span class="hljs-attribute">display</span>: none;</span><br><span class="language-css">        &#125;</span><br><span class="language-css"></span><br><span class="language-css">        <span class="hljs-selector-id">#myMenu</span> <span class="hljs-selector-tag">li</span>&#123;</span><br><span class="language-css">            <span class="hljs-attribute">border-bottom</span>: <span class="hljs-number">1px</span> solid <span class="hljs-number">#ccc</span>;</span><br><span class="language-css">            <span class="hljs-attribute">padding</span>: <span class="hljs-number">5px</span> <span class="hljs-number">10px</span>;</span><br><span class="language-css">            <span class="hljs-attribute">cursor</span>: pointer;</span><br><span class="language-css">        &#125;</span><br><span class="language-css"></span><br><span class="language-css">        <span class="hljs-selector-id">#myMenu</span> <span class="hljs-selector-tag">li</span><span class="hljs-selector-pseudo">:hover</span>&#123;</span><br><span class="language-css">            <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#ccc</span>;</span><br><span class="language-css">        &#125;</span><br><span class="language-css">    </span><span class="hljs-tag">&lt;/<span class="hljs-name">style</span>&gt;</span><br><span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span><br>    <br>    <span class="hljs-tag">&lt;<span class="hljs-name">ul</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;myMenu&quot;</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>右键想干什么？<span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>想看源代码？<span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>还是想审查元素？<span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span><br>    <span class="hljs-tag">&lt;/<span class="hljs-name">ul</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="language-javascript"></span><br><span class="language-javascript">    <span class="hljs-keyword">var</span> myMenu = <span class="hljs-variable language_">document</span>.<span class="hljs-title function_">getElementById</span>(<span class="hljs-string">&quot;myMenu&quot;</span>);</span><br><span class="language-javascript"><span class="hljs-variable language_">document</span>.<span class="hljs-title function_">addEventListener</span>(<span class="hljs-string">&quot;contextmenu&quot;</span>, <span class="hljs-keyword">function</span>(<span class="hljs-params">event</span>)&#123;</span><br><span class="language-javascript">    event.<span class="hljs-title function_">preventDefault</span>();</span><br><span class="language-javascript">    myMenu.<span class="hljs-property">style</span>.<span class="hljs-property">display</span> = <span class="hljs-string">&quot;block&quot;</span>;</span><br><span class="language-javascript">    <span class="hljs-comment">//获取鼠标视口位置</span></span><br><span class="language-javascript">    myMenu.<span class="hljs-property">style</span>.<span class="hljs-property">top</span> = event.<span class="hljs-property">clientY</span> + <span class="hljs-string">&quot;px&quot;</span>;</span><br><span class="language-javascript">    myMenu.<span class="hljs-property">style</span>.<span class="hljs-property">left</span> = event.<span class="hljs-property">clientX</span> + <span class="hljs-string">&quot;px&quot;</span>;</span><br><span class="language-javascript">&#125;);</span><br><span class="language-javascript"></span><br><span class="language-javascript"><span class="hljs-variable language_">document</span>.<span class="hljs-title function_">addEventListener</span>(<span class="hljs-string">&quot;click&quot;</span>, <span class="hljs-keyword">function</span>(<span class="hljs-params">event</span>)&#123;</span><br><span class="language-javascript">    myMenu.<span class="hljs-property">style</span>.<span class="hljs-property">display</span> = <span class="hljs-string">&quot;none&quot;</span>;</span><br><span class="language-javascript">&#125;);</span><br><span class="language-javascript"></span><br><span class="language-javascript">    </span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span><br><span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span><br><span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span><br></code></pre></td></tr></table></figure>

<h5 id="1-8-3-Mouse-事件"><a href="#1-8-3-Mouse-事件" class="headerlink" title="1.8.3 Mouse 事件"></a>1.8.3 Mouse 事件</h5><p>由鼠标或类似用户动作触发的事件：</p>
<table>
<thead>
<tr>
<th align="left">属性</th>
<th align="left">值</th>
<th align="left">描述</th>
</tr>
</thead>
<tbody><tr>
<td align="left">ondrag</td>
<td align="left">script</td>
<td align="left">元素被拖动时运行的脚本。</td>
</tr>
<tr>
<td align="left">ondragend</td>
<td align="left">script</td>
<td align="left">在拖动操作末端运行的脚本。</td>
</tr>
<tr>
<td align="left">ondragenter</td>
<td align="left">script</td>
<td align="left">当元素元素已被拖动到有效拖放区域时运行的脚本。</td>
</tr>
<tr>
<td align="left">ondragleave</td>
<td align="left">script</td>
<td align="left">当元素离开有效拖放目标时运行的脚本。</td>
</tr>
<tr>
<td align="left">ondragover</td>
<td align="left">script</td>
<td align="left">当元素在有效拖放目标上正在被拖动时运行的脚本。</td>
</tr>
<tr>
<td align="left">ondragstart</td>
<td align="left">script</td>
<td align="left">在拖动操作开端运行的脚本。</td>
</tr>
<tr>
<td align="left">ondrop</td>
<td align="left">script</td>
<td align="left">当被拖元素正在被拖放时运行的脚本。</td>
</tr>
<tr>
<td align="left">onmousewheel</td>
<td align="left">script</td>
<td align="left">当鼠标滚轮正在被滚动时运行的脚本。</td>
</tr>
<tr>
<td align="left">onscroll</td>
<td align="left">script</td>
<td align="left">当元素滚动条被滚动时运行的脚本。</td>
</tr>
</tbody></table>
<h5 id="1-8-4-Media-事件"><a href="#1-8-4-Media-事件" class="headerlink" title="1.8.4 Media 事件"></a>1.8.4 Media 事件</h5><p>由媒介（比如视频、图像和音频）触发的事件（适用于所有 HTML 元素，但常见于媒介元素中，比如 <code>&lt;audio&gt;、&lt;embed&gt;、&lt;img&gt;、&lt;object&gt; 以及 &lt;video&gt;</code>）:</p>
<table>
<thead>
<tr>
<th align="left">属性</th>
<th align="left">值</th>
<th align="left">描述</th>
</tr>
</thead>
<tbody><tr>
<td align="left">oncanplay</td>
<td align="left">script</td>
<td align="left">当文件就绪可以开始播放时运行的脚本（缓冲已足够开始时）。</td>
</tr>
<tr>
<td align="left">oncanplaythrough</td>
<td align="left">script</td>
<td align="left">当媒介能够无需因缓冲而停止即可播放至结尾时运行的脚本。</td>
</tr>
<tr>
<td align="left">ondurationchange</td>
<td align="left">script</td>
<td align="left">当媒介长度改变时运行的脚本。</td>
</tr>
<tr>
<td align="left">onemptied</td>
<td align="left">script</td>
<td align="left">当发生故障并且文件突然不可用时运行的脚本（比如连接意外断开时）。</td>
</tr>
<tr>
<td align="left">onended</td>
<td align="left">script</td>
<td align="left">当媒介已到达结尾时运行的脚本（可发送类似“感谢观看”之类的消息）。</td>
</tr>
<tr>
<td align="left">onerror</td>
<td align="left">script</td>
<td align="left">当在文件加载期间发生错误时运行的脚本。</td>
</tr>
<tr>
<td align="left">onloadeddata</td>
<td align="left">script</td>
<td align="left">当媒介数据已加载时运行的脚本。</td>
</tr>
<tr>
<td align="left">onloadedmetadata</td>
<td align="left">script</td>
<td align="left">当元数据（比如分辨率和时长）被加载时运行的脚本。</td>
</tr>
<tr>
<td align="left">onloadstart</td>
<td align="left">script</td>
<td align="left">在文件开始加载且未实际加载任何数据前运行的脚本。</td>
</tr>
<tr>
<td align="left">onpause</td>
<td align="left">script</td>
<td align="left">当媒介被用户或程序暂停时运行的脚本。</td>
</tr>
<tr>
<td align="left">onplay</td>
<td align="left">script</td>
<td align="left">当媒介已就绪可以开始播放时运行的脚本。</td>
</tr>
<tr>
<td align="left">onplaying</td>
<td align="left">script</td>
<td align="left">当媒介已开始播放时运行的脚本。</td>
</tr>
<tr>
<td align="left">onprogress</td>
<td align="left">script</td>
<td align="left">当浏览器正在获取媒介数据时运行的脚本。</td>
</tr>
<tr>
<td align="left">onratechange</td>
<td align="left">script</td>
<td align="left">每当回放速率改变时运行的脚本（比如当用户切换到慢动作或快进模式）。</td>
</tr>
<tr>
<td align="left">onreadystatechange</td>
<td align="left">script</td>
<td align="left">每当就绪状态改变时运行的脚本（就绪状态监测媒介数据的状态）。</td>
</tr>
<tr>
<td align="left">onseeked</td>
<td align="left">script</td>
<td align="left">当 seeking 属性设置为 false（指示定位已结束）时运行的脚本。</td>
</tr>
<tr>
<td align="left">onseeking</td>
<td align="left">script</td>
<td align="left">当 seeking 属性设置为 true（指示定位是活动的）时运行的脚本。</td>
</tr>
<tr>
<td align="left">onstalled</td>
<td align="left">script</td>
<td align="left">在浏览器不论何种原因未能取回媒介数据时运行的脚本。</td>
</tr>
<tr>
<td align="left">onsuspend</td>
<td align="left">script</td>
<td align="left">在媒介数据完全加载之前不论何种原因终止取回媒介数据时运行的脚本。</td>
</tr>
<tr>
<td align="left">ontimeupdate</td>
<td align="left">script</td>
<td align="left">当播放位置改变时（比如当用户快进到媒介中一个不同的位置时）运行的脚本。</td>
</tr>
<tr>
<td align="left">onvolumechange</td>
<td align="left">script</td>
<td align="left">每当音量改变时（包括将音量设置为静音）时运行的脚本。</td>
</tr>
<tr>
<td align="left">onwaiting</td>
<td align="left">script</td>
<td align="left">当媒介已停止播放但打算继续播放时（比如当媒介暂停已缓冲更多数据）运行脚本</td>
</tr>
</tbody></table>
<h4 id="1-9-video"><a href="#1-9-video" class="headerlink" title="1.9 video"></a>1.9 video</h4><p><strong>1、 定义和用法</strong></p>
<p><code>&lt;video&gt;</code> 标签定义视频，比如电影片段或其他视频流。</p>
<figure class="highlight abnf"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><code class="hljs abnf">&lt;video width<span class="hljs-operator">=</span><span class="hljs-string">&quot;320&quot;</span> height<span class="hljs-operator">=</span><span class="hljs-string">&quot;240&quot;</span> controls&gt;<br>    &lt;source src<span class="hljs-operator">=</span><span class="hljs-string">&quot;movie.mp4&quot;</span> type<span class="hljs-operator">=</span><span class="hljs-string">&quot;video/mp4&quot;</span>&gt;<br>    &lt;source src<span class="hljs-operator">=</span><span class="hljs-string">&quot;movie.ogg&quot;</span> type<span class="hljs-operator">=</span><span class="hljs-string">&quot;video/ogg&quot;</span>&gt;<br>    您的浏览器不支持 video 标签。<br>&lt;/video&gt;<br></code></pre></td></tr></table></figure>

<p><strong>2、标签定义及使用说明</strong></p>
<p>目前，<code>&lt;video&gt;</code> 元素支持三种视频格式：MP4、WebM、Ogg。</p>
<table>
<thead>
<tr>
<th align="left">浏览器</th>
<th align="left">MP4</th>
<th align="left">WebM</th>
<th align="left">Ogg</th>
</tr>
</thead>
<tbody><tr>
<td align="left">Internet Explorer</td>
<td align="left">YES</td>
<td align="left">NO</td>
<td align="left">NO</td>
</tr>
<tr>
<td align="left">Chrome</td>
<td align="left">YES</td>
<td align="left">YES</td>
<td align="left">YES</td>
</tr>
<tr>
<td align="left">Firefox</td>
<td align="left">YES 从 Firefox 21 版本开始 Linux 系统从 Firefox 30 开始</td>
<td align="left">YES</td>
<td align="left">YES</td>
</tr>
<tr>
<td align="left">Safari</td>
<td align="left">YES</td>
<td align="left">NO</td>
<td align="left">NO</td>
</tr>
<tr>
<td align="left">Opera</td>
<td align="left">YES 从 Opera 25 版本开始</td>
<td align="left">YES</td>
<td align="left">YES</td>
</tr>
</tbody></table>
<ul>
<li>MP4 = MPEG 4文件使用 H264 视频编解码器和AAC音频编解码器</li>
<li>WebM = WebM 文件使用 VP8 视频编解码器和 Vorbis 音频编解码器</li>
<li>Ogg = Ogg 文件使用 Theora 视频编解码器和 Vorbis音频编解码器</li>
</ul>
<p><strong>3、属性</strong></p>
<table>
<thead>
<tr>
<th align="left">属性</th>
<th align="left">值</th>
<th align="left">描述</th>
</tr>
</thead>
<tbody><tr>
<td align="left">autoplay</td>
<td align="left">autoplay</td>
<td align="left">如果出现该属性，则视频在就绪后马上播放。</td>
</tr>
<tr>
<td align="left">controls</td>
<td align="left">controls</td>
<td align="left">如果出现该属性，则向用户显示控件，比如播放按钮。</td>
</tr>
<tr>
<td align="left">height</td>
<td align="left"><em>pixels</em></td>
<td align="left">设置视频播放器的高度。</td>
</tr>
<tr>
<td align="left">loop</td>
<td align="left">loop</td>
<td align="left">如果出现该属性，则当媒介文件完成播放后再次开始播放。</td>
</tr>
<tr>
<td align="left">muted</td>
<td align="left">muted</td>
<td align="left">规定视频的音频输出应该被静音。</td>
</tr>
<tr>
<td align="left">poster</td>
<td align="left"><em>URL</em></td>
<td align="left">规定视频下载时显示的图像，或者在用户点击播放按钮前显示的图像。</td>
</tr>
<tr>
<td align="left">preload</td>
<td align="left">preload</td>
<td align="left">如果出现该属性，则视频在页面加载时进行加载，并预备播放。如果使用 “autoplay”，则忽略该属性。</td>
</tr>
<tr>
<td align="left">src</td>
<td align="left"><em>url</em></td>
<td align="left">要播放的视频的 URL。</td>
</tr>
<tr>
<td align="left">width</td>
<td align="left"><em>pixels</em></td>
<td align="left">设置视频播放器的宽度。</td>
</tr>
</tbody></table>
<p><strong>4、使用DOM控制</strong></p>
<p>HTML5 <code>&lt;video&gt;</code> 元素同样拥有方法、属性和事件。</p>
<p>其中的方法用于播放、暂停以及加载等。其中的属性（比如时长、音量等）可以被读取或设置。其中的 DOM 事件能够通知您，比方说，<video> 元素开始播放、已暂停，已停止，等等。</p>
<table>
<thead>
<tr>
<th align="left">方法</th>
<th align="left">属性</th>
<th align="left">事件</th>
</tr>
</thead>
<tbody><tr>
<td align="left">play()</td>
<td align="left">currentSrc</td>
<td align="left">play</td>
</tr>
<tr>
<td align="left">pause()</td>
<td align="left">currentTime</td>
<td align="left">pause</td>
</tr>
<tr>
<td align="left">load()</td>
<td align="left">videoWidth</td>
<td align="left">progress</td>
</tr>
<tr>
<td align="left">canPlayType</td>
<td align="left">videoHeight</td>
<td align="left">error</td>
</tr>
<tr>
<td align="left"></td>
<td align="left">duration</td>
<td align="left">timeupdate</td>
</tr>
<tr>
<td align="left"></td>
<td align="left">ended</td>
<td align="left">ended</td>
</tr>
<tr>
<td align="left"></td>
<td align="left">error</td>
<td align="left">abort</td>
</tr>
<tr>
<td align="left"></td>
<td align="left">paused</td>
<td align="left">empty</td>
</tr>
<tr>
<td align="left"></td>
<td align="left">muted</td>
<td align="left">emptied</td>
</tr>
<tr>
<td align="left"></td>
<td align="left">seeking</td>
<td align="left">waiting</td>
</tr>
<tr>
<td align="left"></td>
<td align="left">volume</td>
<td align="left">loadedmetadata</td>
</tr>
<tr>
<td align="left"></td>
<td align="left">height</td>
<td align="left"></td>
</tr>
<tr>
<td align="left"></td>
<td align="left">width</td>
<td align="left"></td>
</tr>
</tbody></table>
<p><strong>注释：</strong>在所有属性中，只有 videoWidth 和 videoHeight 属性是立即可用的。在视频的元数据已加载后，其他属性才可用。</p>
<h4 id="1-10-audio"><a href="#1-10-audio" class="headerlink" title="1.10 audio"></a>1.10 audio</h4><p><strong>1、 定义和用法</strong></p>
<p><code>&lt;audio&gt;</code> 标签定义声音，比如音乐或其他音频流。</p>
<figure class="highlight stylus"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs stylus">&lt;<span class="hljs-selector-tag">audio</span> <span class="hljs-attribute">src</span>=<span class="hljs-string">&quot;someaudio.wav&quot;</span>&gt;<br>您的浏览器不支持 <span class="hljs-selector-tag">audio</span> 标签。<br>&lt;/audio&gt;<br></code></pre></td></tr></table></figure>

<p><strong>2、音频格式</strong></p>
<p>当前，audio 元素支持三种音频格式：</p>
<table>
<thead>
<tr>
<th align="left"></th>
<th align="left">IE 9</th>
<th align="left">Firefox 3.5</th>
<th align="left">Opera 10.5</th>
<th align="left">Chrome 3.0</th>
<th align="left">Safari 3.0</th>
</tr>
</thead>
<tbody><tr>
<td align="left">Ogg Vorbis</td>
<td align="left"></td>
<td align="left">√</td>
<td align="left">√</td>
<td align="left">√</td>
<td align="left"></td>
</tr>
<tr>
<td align="left">MP3</td>
<td align="left">√</td>
<td align="left"></td>
<td align="left"></td>
<td align="left">√</td>
<td align="left">√</td>
</tr>
<tr>
<td align="left">Wav</td>
<td align="left"></td>
<td align="left">√</td>
<td align="left">√</td>
<td align="left"></td>
<td align="left">√</td>
</tr>
</tbody></table>
<p><strong>3、属性</strong></p>
<table>
<thead>
<tr>
<th align="left">属性</th>
<th align="left">描述</th>
</tr>
</thead>
<tbody><tr>
<td align="left">audioTracks</td>
<td align="left">返回表示可用音频轨道的 AudioTrackList 对象。</td>
</tr>
<tr>
<td align="left">autoplay</td>
<td align="left">设置或返回是否在就绪（加载完成）后随即播放音频。</td>
</tr>
<tr>
<td align="left">buffered</td>
<td align="left">返回表示音频已缓冲部分的 TimeRanges 对象。</td>
</tr>
<tr>
<td align="left">controller</td>
<td align="left">返回表示音频当前媒体控制器的 MediaController 对象。</td>
</tr>
<tr>
<td align="left">controls</td>
<td align="left">设置或返回音频是否应该显示控件（比如播放/暂停等）。</td>
</tr>
<tr>
<td align="left">crossOrigin</td>
<td align="left">设置或返回音频的 CORS 设置。</td>
</tr>
<tr>
<td align="left">currentSrc</td>
<td align="left">返回当前音频的 URL。</td>
</tr>
<tr>
<td align="left">currentTime</td>
<td align="left">设置或返回音频中的当前播放位置（以秒计）。</td>
</tr>
<tr>
<td align="left">defaultMuted</td>
<td align="left">设置或返回音频默认是否静音。</td>
</tr>
<tr>
<td align="left">defaultPlaybackRate</td>
<td align="left">设置或返回音频的默认播放速度。</td>
</tr>
<tr>
<td align="left">duration</td>
<td align="left">返回音频的长度（以秒计）。</td>
</tr>
<tr>
<td align="left">ended</td>
<td align="left">返回音频的播放是否已结束。</td>
</tr>
<tr>
<td align="left">error</td>
<td align="left">返回表示音频错误状态的 MediaError 对象。</td>
</tr>
<tr>
<td align="left">loop</td>
<td align="left">设置或返回音频是否应在结束时再次播放。</td>
</tr>
<tr>
<td align="left">mediaGroup</td>
<td align="left">设置或返回音频所属媒介组合的名称。</td>
</tr>
<tr>
<td align="left">muted</td>
<td align="left">设置或返回是否关闭声音。</td>
</tr>
<tr>
<td align="left">networkState</td>
<td align="left">返回音频的当前网络状态。</td>
</tr>
<tr>
<td align="left">paused</td>
<td align="left">设置或返回音频是否暂停。</td>
</tr>
<tr>
<td align="left">playbackRate</td>
<td align="left">设置或返回音频播放的速度。</td>
</tr>
<tr>
<td align="left">played</td>
<td align="left">返回表示音频已播放部分的 TimeRanges 对象。</td>
</tr>
<tr>
<td align="left">preload</td>
<td align="left">设置或返回音频的 preload 属性的值。</td>
</tr>
<tr>
<td align="left">readyState</td>
<td align="left">返回音频当前的就绪状态。</td>
</tr>
<tr>
<td align="left">seekable</td>
<td align="left">返回表示音频可寻址部分的 TimeRanges 对象。</td>
</tr>
<tr>
<td align="left">seeking</td>
<td align="left">返回用户当前是否正在音频中进行查找。</td>
</tr>
<tr>
<td align="left">src</td>
<td align="left">设置或返回音频的 src 属性的值。</td>
</tr>
<tr>
<td align="left">textTracks</td>
<td align="left">返回表示可用文本轨道的 TextTrackList 对象。</td>
</tr>
<tr>
<td align="left">volume</td>
<td align="left">设置或返回音频的音量。</td>
</tr>
</tbody></table>
<p><strong>4、方法</strong></p>
<table>
<thead>
<tr>
<th align="left">方法</th>
<th align="left">描述</th>
</tr>
</thead>
<tbody><tr>
<td align="left">addTextTrack()</td>
<td align="left">向音频添加新的文本轨道。</td>
</tr>
<tr>
<td align="left">canPlayType()</td>
<td align="left">检查浏览器是否能够播放指定的音频类型。</td>
</tr>
<tr>
<td align="left">fastSeek()</td>
<td align="left">在音频播放器中指定播放时间。</td>
</tr>
<tr>
<td align="left">getStartDate()</td>
<td align="left">返回新的 Date 对象，表示当前时间线偏移量。</td>
</tr>
<tr>
<td align="left">load()</td>
<td align="left">重新加载音频元素。</td>
</tr>
<tr>
<td align="left">play()</td>
<td align="left">开始播放音频。</td>
</tr>
<tr>
<td align="left">pause()</td>
<td align="left">暂停当前播放的音频。</td>
</tr>
</tbody></table>
<p><strong>5、事件</strong></p>
<p>play 播放事件 可判断歌曲是否正在播放中<br>pause 暂停事件 判断歌曲是否暂停<br>loadstart，durationchange，loadeddata，progress，canplay，canplaythrough。（这些事件在加载过程中是按以上顺序触发的）<br>以上这些事件可以通过事件监听对其做相应处理。</p>

                
              </div>
            
            <hr/>
            <div>
              <div class="post-metas my-3">
  
    <div class="post-meta mr-3 d-flex align-items-center">
      <i class="iconfont icon-category"></i>
      

<span class="category-chains">
  
  
    
      <span class="category-chain">
        
  <a href="/categories/study/" class="category-chain-item">study</a>
  
  

      </span>
    
  
</span>

    </div>
  
  
    <div class="post-meta">
      <i class="iconfont icon-tags"></i>
      
        <a href="/tags/HTML/">#HTML</a>
      
    </div>
  
</div>


              
  

  <div class="license-box my-3">
    <div class="license-title">
      <div>HTML5</div>
      <div>https://moewang0321.github.io/2019/09/23/2019-09-23-HTML5/</div>
    </div>
    <div class="license-meta">
      
        <div class="license-meta-item">
          <div>作者</div>
          <div>Moe Wang</div>
        </div>
      
      
        <div class="license-meta-item license-meta-date">
          <div>发布于</div>
          <div>2019年9月23日</div>
        </div>
      
      
      
        <div class="license-meta-item">
          <div>许可协议</div>
          <div>
            
              
              
                <a target="_blank" href="https://creativecommons.org/licenses/by/4.0/">
                  <span class="hint--top hint--rounded" aria-label="BY - 署名">
                    <i class="iconfont icon-by"></i>
                  </span>
                </a>
              
            
          </div>
        </div>
      
    </div>
    <div class="license-icon iconfont"></div>
  </div>



              
                <div class="post-prevnext my-3">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2019/09/27/2019-09-27-%E8%B4%9D%E5%A1%9E%E5%B0%94%E6%9B%B2%E7%BA%BF/" title="自定义三阶贝塞尔曲线">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">自定义三阶贝塞尔曲线</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2019/08/09/2019-08-09-%E8%AF%A6%E8%A7%A3this/" title="详解this">
                        <span class="hidden-mobile">详解this</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
  
  
    <article id="comments" lazyload>
      
    <div id="giscus" class="giscus"></div>
    <script type="text/javascript">
      Fluid.utils.loadComments('#giscus', function() {
        var options = {"repo":"moewang0321/moewang0321.github.io","repo-id":"MDEwOlJlcG9zaXRvcnkyMDEyNDI0NTY=","category":"Show and tell","category-id":"DIC_kwDOC_63WM4CUMsH","theme-light":"light_protanopia","theme-dark":"dark_dimmed","mapping":"pathname","reactions-enabled":1,"emit-metadata":1,"input-position":"top","loading":"lazy","lang":"zh-CN"};
        var attributes = {};
        for (let option in options) {
          if (!option.startsWith('theme-')) {
            var key = option.startsWith('data-') ? option : 'data-' + option;
            attributes[key] = options[option];
          }
        }
        var light = 'light_protanopia';
        var dark = 'dark_dimmed';
        window.GiscusThemeLight = light;
        window.GiscusThemeDark = dark;
        attributes['data-theme'] = document.documentElement.getAttribute('data-user-color-scheme') === 'dark' ? dark : light;
        for (let attribute in attributes) {
          var value = attributes[attribute];
          if (value === undefined || value === null || value === '') {
            delete attributes[attribute];
          }
        }
        var s = document.createElement('script');
        s.setAttribute('src', 'https://giscus.app/client.js');
        s.setAttribute('crossorigin', 'anonymous');
        for (let attribute in attributes) {
          s.setAttribute(attribute, attributes[attribute]);
        }
        var ss = document.getElementsByTagName('script');
        var e = ss.length > 0 ? ss[ss.length - 1] : document.head || document.documentElement;
        e.parentNode.insertBefore(s, e.nextSibling);
      });
    </script>
    <noscript>Please enable JavaScript to view the comments</noscript>


    </article>
  


          </article>
        </div>
      </div>
    </div>

    <div class="side-col d-none d-lg-block col-lg-2">
      
  <aside class="sidebar" style="margin-left: -1rem">
    <div id="toc">
  <p class="toc-header">
    <i class="iconfont icon-list"></i>
    <span>目录</span>
  </p>
  <div class="toc-body" id="toc-body"></div>
</div>



  </aside>


    </div>
  </div>
</div>





  



  



  



  



  







    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v" for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>

    

    
  </main>

  <footer>
    <div class="footer-inner">
  
    <div class="footer-content">
       <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a> <i class="iconfont icon-love"></i> <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>Fluid</span></a> 
    </div>
  
  
  
  
</div>

  </footer>

  <!-- Scripts -->
  
  <script  src="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://lib.baomitu.com/jquery/3.6.0/jquery.min.js" ></script>
<script  src="https://lib.baomitu.com/twitter-bootstrap/4.6.1/js/bootstrap.min.js" ></script>
<script  src="/js/events.js" ></script>
<script  src="/js/plugins.js" ></script>


  <script  src="https://lib.baomitu.com/typed.js/2.0.12/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var subtitle = document.getElementById('subtitle');
      if (!subtitle || !typing) {
        return;
      }
      var text = subtitle.getAttribute('data-typed-text');
      
        typing(text);
      
    })(window, document);
  </script>




  
    <script  src="/js/img-lazyload.js" ></script>
  




  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/tocbot/4.18.2/tocbot.min.js', function() {
    var toc = jQuery('#toc');
    if (toc.length === 0 || !window.tocbot) { return; }
    var boardCtn = jQuery('#board-ctn');
    var boardTop = boardCtn.offset().top;

    window.tocbot.init(Object.assign({
      tocSelector     : '#toc-body',
      contentSelector : '.markdown-body',
      linkClass       : 'tocbot-link',
      activeLinkClass : 'tocbot-active-link',
      listClass       : 'tocbot-list',
      isCollapsedClass: 'tocbot-is-collapsed',
      collapsibleClass: 'tocbot-is-collapsible',
      scrollSmooth    : true,
      includeTitleTags: true,
      headingsOffset  : -boardTop,
    }, CONFIG.toc));
    if (toc.find('.toc-list-item').length > 0) {
      toc.css('visibility', 'visible');
    }

    Fluid.events.registerRefreshCallback(function() {
      if ('tocbot' in window) {
        tocbot.refresh();
        var toc = jQuery('#toc');
        if (toc.length === 0 || !tocbot) {
          return;
        }
        if (toc.find('.toc-list-item').length > 0) {
          toc.css('visibility', 'visible');
        }
      }
    });
  });
</script>


  <script src=https://lib.baomitu.com/clipboard.js/2.0.11/clipboard.min.js></script>

  <script>Fluid.plugins.codeWidget();</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/anchor-js/4.3.1/anchor.min.js', function() {
    window.anchors.options = {
      placement: CONFIG.anchorjs.placement,
      visible  : CONFIG.anchorjs.visible
    };
    if (CONFIG.anchorjs.icon) {
      window.anchors.options.icon = CONFIG.anchorjs.icon;
    }
    var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
    var res = [];
    for (var item of el) {
      res.push('.markdown-body > ' + item.trim());
    }
    if (CONFIG.anchorjs.placement === 'left') {
      window.anchors.options.class = 'anchorjs-link-left';
    }
    window.anchors.add(res.join(', '));

    Fluid.events.registerRefreshCallback(function() {
      if ('anchors' in window) {
        anchors.removeAll();
        var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
        var res = [];
        for (var item of el) {
          res.push('.markdown-body > ' + item.trim());
        }
        if (CONFIG.anchorjs.placement === 'left') {
          anchors.options.class = 'anchorjs-link-left';
        }
        anchors.add(res.join(', '));
      }
    });
  });
</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.js', function() {
    Fluid.plugins.fancyBox();
  });
</script>


  <script>Fluid.plugins.imageCaption();</script>

  <script  src="/js/local-search.js" ></script>





<!-- 主题的启动项，将它保持在最底部 -->
<!-- the boot of the theme, keep it at the bottom -->
<script  src="/js/boot.js" ></script>


  

  <noscript>
    <div class="noscript-warning">博客在允许 JavaScript 运行的环境下浏览效果更佳</div>
  </noscript>
</body>
</html>
